/*******************************************************************************

                           REPLICATION FILE

THE SPILLOVER (AND DIRECT) EFFECTS OF WORKPLACE CONTACT ON INTERGROUP ATTITUDES

                            ROBERT JENSEN
                    REVIEW OF ECONOMICS AND STATISTICS

                           AUGUST 21, 2025
                       EXECUTED USING STATA 15.1
					   
*******************************************************************************/




/*SET UP ENVIRONMENT*/
	#delimit;
	clear;
	set more 1;

	cap log close;
	cls;
	eststo clear;

	log using temp_log, replace;



/******************************************************************************/
/******************************************************************************/
/*      REPLACE PART IN QUOTES TO CHANGE TO YOUR PREFERRED DIRECTORY HERE     */
/******************************************************************************/
/******************************************************************************/
	global CONTACT_REPLIC "C:/Contact/Replication" ;
	
	
	
	use "${CONTACT_REPLIC}/RESTAT_Replication_Data.dta";



/******************************************************************************
						VARIABLE LIBRARY
*******************************************************************************
						
Variable Name			Description
--------------------------------------------------------------------------------
worker_id 				ID of the worker who applied for a BPO job. For workers, this
							is their own ID. For family/friends, it is the ID of the
							worker who designated them as a friend/family member.
worker 					=1 if respondent is the applicant/worker, 
							=0 if respondent is family/friend of the applicant/worker.
muslim_partner 			Binary variable, =1 if randomly assigned Muslim partner, 
							=0 if assigned a Hindu partner
age 					Respondent's age, in years
female 					Binary, =1 if respondent is female, =0 otherwise.
fathers_ed 				Respondent's father's highest level of education
mothers_ed 				Respondent's mother's highest level of education
wealth_index 			Index of respondent's household wealth from 1 to 5.
family_size 			# people in respondent's household 					
interact_with_worker 	How often family/friend respondent reports interacting 
							w/ worker: 
								1=Never
								2=Rarely/not very often;
								3=Sometimes
								4=Often
								5=All the time/every day
have_muslim_friend 		Binary, =1 if respondent says they have a Muslim friend
attriter 				Binary, =1 if respondent could not be surveyed at follow-up
how_much_interact 		How often respondent reports interacting with Muslims: 
								1=Never
								2=Rarely/not very often;
								3=Sometimes
								4=Often
								5=All the time/every day
can_be_friends 			Respondent agrees/disagrees with the statement 
							"Hindus & Muslims can be friends": 
								1=Strongly disagree
								2=Somewhat disagree
								3=Neither agree nor disagree
								4=Somewhat agree
								5=Strongly agree
can_trust 				Respondent agrees/disagrees with the statement 
							"Hindus & Muslims can trust each other"
								1=Strongly disagree
								2=Somewhat disagree
								3=Neither agree nor disagree
								4=Somewhat agree
								5=Strongly agree
treated_unfair 			Respondent agrees/disagrees with the statement 
							"Muslims sometimes face discrimination or unfair 
							treatment in society" 
								1=Strongly disagree
								2=Somewhat disagree
								3=Neither agree nor disagree
								4=Somewhat agree
								5=Strongly agree												
quiz 					# Correct answers to questions about Islam (out of 3)

*******************************************************************************/





/******************************************************************************
					     TABLE 1. COVARIATE BALANCE
*******************************************************************************/

		/*First show the results in the Results window in Stata*/
			
			local vars female age fathers_ed mothers_ed wealth_index family_size attriter ;

			/*TOP PANEL: WORKERS*/				
				foreach v of local vars {;
					di as txt _n "     ******************************************************************************" ;
					di as txt _n "             ttest for `v', by muslim_partner, for workers        " ;
					di as txt _n "     *****************************************************************************" ;
					ttest `v' if worker==1 & !missing(muslim_partner, `v'), by(muslim_partner) unequal;
				} ;
				
			/*BOTTOM PANEL: FAMILY/FRIENDS*/
				foreach v of local vars {;
					di as txt _n "     ******************************************************************************" ;
					di as txt _n "         ttest for `v', by muslim_partner, for family/friends        " ;
					di as txt _n "     *****************************************************************************" ;
					ttest `v' if worker==0 & !missing(muslim_partner, `v'), by(muslim_partner) unequal;
				} ;
					di as txt _n "----- ttest for interact_with_worker (if worker==0; by muslim_partner) -----" ;
					ttest interact_with_worker if worker==0 & !missing(muslim_partner, interact_with_worker), by(muslim_partner) unequal;

					
		/*Output the results to tables for LaTeX*/			

			/*TOP PANEL: WORKERS*/
				estpost ttest female age fathers_ed mothers_ed wealth_index family_size attriter if worker==1, by(muslim_partner) unequal;
				esttab using "${CONTACT_REPLIC}/CovarBalanceW.tex",
				 replace 
				 cells("mu_1(fmt(2)) mu_2 b(star) se(par) count(fmt(0))") 
				 star(* 0.1 ** 0.05 *** 0.01) 
				 nonumber 
				 booktabs 
				 noobs 
				 title("Test of Covariate Balance \label{balance_test}") 
				 
				  collabels("Hindu Partner" "Muslim Partner" "Difference" "Std. Error" "N") 
				 addnote("Note: Means and tests of covariate balance for those assigned Hindu or Muslim Partner.") 
				 coeflabels(female "Female" 
					age "Age"
					fathers_ed "Father's years of educ."
					mothers_ed "Mother's years of educ."
					wealth_index "Index household wealth"
					family_size "Family Size"
					attriter "Attrition"					
				 )
					;
					
				eststo clear;			
		
			/*BOTTOM PANEL: FAMILY/FRIENDS*/
				estpost ttest female age fathers_ed mothers_ed wealth_index family_size attriter interact_with_worker if worker==0, by(muslim_partner) unequal;
				esttab using "${CONTACT_REPLIC}/CovarBalanceNW.tex",
				 replace 
				 cells("mu_1(fmt(2)) mu_2 b(star) se(par) count(fmt(0))") 
				 star(* 0.1 ** 0.05 *** 0.01) 
				 nonumber 
				 booktabs 
				 noobs 
				 title("Test of Covariate Balance \label{balance_test}") 
				 
				  collabels("Hindu Partner" "Muslim Partner" "Difference" "Std. Error" "N") 
				 addnote("Note: Means and tests of covariate balance for those assigned  Hindu or Muslim Partner.") 
				 coeflabels(female "Female" 
					age "Age"
					fathers_ed "Father's years of educ."
					mothers_ed "Mother's years of educ."
					wealth_index "Index household wealth"
					family_size "Family Size"					
					interact_with_worker "Frequency interact w/ worker"
					attriter "Attrition"
				 )
				;

		
		
				
/******************************************************************************
			  TABLE 2. MEANS AND DISTIBUTIONS OF DEPENDENT VARIABLES
*******************************************************************************/
					
			qui tab how_much_interact, gen(interaction_);
			qui tab treated_unfair, gen(unfair_);
			qui tab can_be_friends, gen(cbf_);
			qui tab can_trust, gen(ctr_);
					
					
			/*First show in Results window*/
			/*Column 1: Family/friends of those applicants/workers assigned a Hindu Partner*/					
				tabstat interaction_* have_muslim_friend unfair_* cbf_* ctr_* quiz if worker==0 & muslim_partner==0, c(stat) stat(mean sd);
			/*Column 2: Family/friends of those applicants/workers assigned a Muslim Partner*/						
				tabstat interaction_* have_muslim_friend unfair_* cbf_* ctr_* quiz if worker==0 & muslim_partner==1, c(stat) stat(mean sd);
			/*Column 3: Workers assigned a Hindu Partner*/		
				tabstat interaction_* have_muslim_friend unfair_* cbf_* ctr_* quiz if worker==1 & muslim_partner==0, c(stat) stat(mean sd);
			/*Column 4: Workers assigned a Muslim Partner*/		
				tabstat interaction_* have_muslim_friend unfair_* cbf_* ctr_* quiz if worker==1 & muslim_partner==1, c(stat) stat(mean sd);
				

				
			/*Output to LaTeX file*/
					eststo clear;	
					eststo group1: estpost tabstat interaction_* have_muslim_friend unfair_* cbf_* ctr_* quiz if worker==0 & muslim_partner==0, c(stat) stat(mean sd);
					eststo group2: estpost tabstat interaction_* have_muslim_friend unfair_* cbf_* ctr_* quiz if worker==0 & muslim_partner==1, c(stat) stat(mean sd);
					eststo group3: estpost tabstat interaction_* have_muslim_friend unfair_* cbf_* ctr_* quiz if worker==1 & muslim_partner==0, c(stat) stat(mean sd);
					eststo group4: estpost tabstat interaction_* have_muslim_friend unfair_* cbf_* ctr_* quiz if worker==1 & muslim_partner==1, c(stat) stat(mean sd);		
							
					 esttab group1 group2 group3 group4 using "${CONTACT_REPLIC}/MeansDepVars",
					  replace 
					  cells("mean(fmt(3))" "sd(par)") 
					 nonumber 
					  mtitle("Non-Worker, Hindu partner" "Non-Worker, Muslim partner" "Worker, Hindu partner" "Worker, Muslim partner" ) 
					  nostar 
					  unstack 
					  booktabs 
					  noobs 
					  title("Means and Distributions of Dependent Variables\label{MeansDepVars}") 
					  collabels(none) 
					 addnote("Note: Means and distributions of dependent variables for treatment and control groups.") 
					  coeflabels(interaction_1 "Never" interaction_2 "Not very often" interaction_3 "Sometimes" interaction_4 "Often" interaction_5 "All the time/every day"
					  have_muslim_friend "Have Muslim Friend?" 
					  unfair_1 "Strongly Disagree" unfair_2 "Somewhat Disagree" unfair_3 "Neither Agree/Disagree" unfair_4 "Somewhat Agree" unfair_5 "Strongly Agree"
					  cbf_1 "Strongly Disagree" cbf_2 "Somewhat Disagree" cbf_3 "Neither Agree/Disagree" cbf_4 "Somewhat Agree" cbf_5 "Strongly Agree"  
					  ctr_1 "Strongly Disagree" ctr_2 "Somewhat Disagree" ctr_3 "Neither Agree/Disagree" ctr_4 "Somewhat Agree" ctr_5 "Strongly Agree"  
					  quiz "# Correct (out of 3)"
					  how_much_interact "Mean"
					  can_trust "Mean"
					  can_be_friends "Mean"
					  treated_unfair "Mean"
					) 
					 ;

					 

					 
/******************************************************************************
	  TABLE 3: EFFECTS OF BEING ASSIGNED MUSLIM PARTNER VS. HINDU PARTNER
*******************************************************************************/

		/*First show the results in the Results window in Stata*/
			local dep_vars how_much_interact have_muslim_friend can_trust can_be_friends treated_unfair quiz;

			/*TOP PANEL: WORKERS*/				
				foreach v of local dep_vars {;
					di as txt _n "     ******************************************************************************" ;
					di as txt _n "             Regression with `v' as dependent variable, for workers        " ;
					di  as txt _n "     *****************************************************************************" ;
					reg `v' muslim_partner female if worker==1, vce(rob);
				} ;

			/*BOTTOM PANEL: FAMILY/FRIENDS*/				
				foreach v of local dep_vars {;
					di as txt _n "     ******************************************************************************" ;
					di as txt _n "         Regression with `v' as dependent variable, for family/friends    " ;
					di as txt _n "     ******************************************************************************" ;
					reg `v' muslim_partner female if worker==0, vce(cluster worker_id);
				} ;
				
				
			/*Output to LaTeX file*/
				eststo clear; 
				eststo: 	reg how_much_interact muslim_partner female if worker==1, vce(rob);
				eststo: 	reg have_muslim_friend muslim_partner female if worker==1, vce(rob);
				eststo: 	reg can_trust muslim_partner female if worker==1, vce(rob);
				eststo: 	reg can_be_friends muslim_partner female if worker==1, vce(rob);
				eststo: 	reg treated_unfair muslim_partner female if worker==1, vce(rob);
				eststo: 	reg quiz muslim_partner female if worker==1, vce(rob);

				esttab using "${CONTACT_REPLIC}/MainRegsW.tex", 
				  se(3) 
				  b(3) 
				  label
				  replace 
				  star(* 0.10 ** 0.05 *** 0.01)
				  title(Effects of Treatment \label{regressionoutput}) 
				  mtitles("Interact" "Friends" "Can Trust" "Can be Friends" "Discrimination" "Knowledge") 
				  keep(muslim_partner) 
				  coeflabels(muslim_partner "Muslim Partner") 
				;
		
				 eststo clear;
				 
				eststo: 	reg how_much_interact muslim_partner female if worker==0, vce(cluster worker_id);
				eststo: 	reg have_muslim_friend muslim_partner female if worker==0, vce(cluster worker_id);
				eststo: 	reg can_trust muslim_partner female if worker==0, vce(cluster worker_id);
				eststo: 	reg can_be_friends muslim_partner female if worker==0, vce(cluster worker_id);
				eststo: 	reg treated_unfair muslim_partner female if worker==0, vce(cluster worker_id);
				eststo: 	reg quiz muslim_partner female if worker==0, vce(cluster worker_id);
				

				esttab using "${CONTACT_REPLIC}/MainRegsNW.tex", 
				  se(3) 
				  b(3) 
				  label
				  replace 
				  star(* 0.10 ** 0.05 *** 0.01)
				  title(Effects of Treatment \label{regressionoutputNW}) 
				  mtitles("Interact" "Friends" "Can Trust" "Can be Friends" "Discrimination" "Knowledge") 
				  keep(muslim_partner) 
				  coeflabels(muslim_partner "Muslim Partner") 
				;

		
	